package com.ruoyi.business.controller;

import com.ruoyi.business.mapper.BusAttachmentMapper;
import com.ruoyi.business.service.BusAttachmentService;
import com.ruoyi.business.service.IBusCarService;
import com.ruoyi.business.service.IBusCustomerService;
import com.ruoyi.business.vo.RentVo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 内容:
 * 作者: cy
 */
@RestController
@RequestMapping("business/rentCar")
@Api(tags = "汽车出租接口管理")
public class RentCarController extends BaseController {
   @Autowired
   private IBusCustomerService customerService;
   @Autowired
   private BusAttachmentService attachmentService;
   @Autowired
   private IBusCarService carService;

   @GetMapping("checkCustomerId")
   @ApiOperation("根据客户的身份证号校验客户信息")
   public AjaxResult checkCustomerId(String identity){
      Boolean flag = customerService.checkCustomerId(identity);
      return toAjax(flag);
   }

   @GetMapping("showCarImgs")
   @ApiOperation("根据车牌号查看车辆大图")
   public AjaxResult showCarImgs(String carNumber){
      List<String> carImgs = attachmentService.selectCarImgs(carNumber);
      return AjaxResult.success(carImgs);

   }
   @GetMapping("toRent")
   @ApiOperation("去租车(将车辆信息展示出来)")
   public AjaxResult toRent(Long carId){
      RentVo rentVo = carService.toRent(carId);
      return AjaxResult.success(rentVo);
   }
   @PostMapping("doRent")
   @ApiOperation("真正的租车")
   public AjaxResult doRent(@RequestBody RentVo rentVo){
      LoginUser loginUser = getLoginUser();
      Boolean flag = carService.realDoRent(rentVo,loginUser);
      return AjaxResult.success(flag ? "租车成功,祝您用车愉快": "租车失败,请重新租车");
   }
}
